<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分店批发管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../res/layui-v2.5.6/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script src="../../../res/js/jquery-3.4.1.min.js"></script>
    <style>
        #myform{
            position: relative;
            top: 15px;
        }
    </style>
</head>
<body>

<form class="layui-form" action="" method="post" lay-filter="myform" id="myform">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">关键：</label>
            <div class="layui-input-inline">
                <input type="text" name="searchParam" id="searchParam" placeholder="请输入关键字" autocomplete="off" class="layui-input">
            </div>
        </div>

<!--        <div class="layui-inline">-->
<!--            <label class="layui-form-label">审核状态：</label>-->
<!--            <div class="layui-input-inline">-->
<!--                <select name="reviewState" id="reviewState" lay-filter="aihao">-->
<!--                    <option value=""></option>-->
<!--                    <option value="0">审核不通过</option>-->
<!--                    <option value="1">等待审核</option>-->
<!--                    <option value="2">财务审核通过</option>-->
<!--                    <option value="3">审核通过</option>-->
<!--                </select>-->
<!--            </div>-->
<!--        </div>-->

        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" lay-submit="" onclick="query()">搜索</button>
            </div>
        </div>

    </div>
</form>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="insertRec">添加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <button class="layui-btn layui-btn-xs" lay-event="edit">查看详情</button>
    <a class="layui-btn layui-btn-xs" lay-event="auditRecord">查询审核详情</a>
    {{#  if(d.isva == 10 || d.isva == 41){ }}
    <button class="layui-btn layui-btn-xs" lay-event="audit">提交审核</button>
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">发票</a>-->
    {{#  } else if(d.isva == 20 || d.isva == 40){ }}
    <button class="layui-btn layui-btn-disabled layui-btn-xs" disabled="disabled" lay-event="audit">提交审核</button>
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">发票</a>-->
    {{#  } }}
</script>

<script src="../../../res/layui-v2.5.6/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    var table = null;
    var perUser = null;
    var openIndex = null;

    layui.use(['table','layer'], function(){
        table = layui.table;
        var $ = layui.$;
        var layer = layui.layer;

        table.render({
            elem: '#test'
            ,url: '../../../immSell/shows'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips'
            }]
            ,title: '用户数据表'
            ,cols: [[
                // {type: 'checkbox', fixed: 'left'},
                {field:'sellId', title:'流水号', width:100, fixed: 'left', unresize: true, sort: true,align:"center"}
                ,{field:'sellCount', title:'销售数量', width:120,align:"center"}
                ,{field:'sellMonty', title:'销售金额', width:120,align:"center"}
                ,{field:'operator', title:'销售人', width:80,align:"center"}
                ,{field:'sellTime', title:'销售时间', width:200,align:"center"}
                ,{field:'isva', title:'状态', width:200, templet: "#typeTpl",align:"center"}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo',align:"center"}
            ]]
            ,page: true
            ,id:'testReload'

        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){

                case 'insertRec':
                    openIndex = layer.open({
                        maxmin: true, //开启最大最小化
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['80%', '90%'], //宽高
                        content: 'Immsellfroms.html',
                        end:function () {
                            //layer.msg("关闭ing");
                        },
                    });
                    break;


                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('真的删除行吗?', function(index){
                    var url = "../../../immSell/deleteById";
                    var datas = {sellId:data.sellId};
                    $.post(url,datas,function (objs) {
                        if (objs.status > 0){
                            console.log(objs.message);
                            layer.close(index);
                            table.reload("testReload");
                        }else {
                            layui.msg('删除失败');
                        }
                    },"json")
                });
            }else if(obj.event === 'auditRecord'){
                console.info(data)
                var marketId = data.sellId;
                //sessionStorage['soId'] = soId;
                //根据采购订单编号查看审核表记录
                openindex = layui.layer.open({
                    type: 2,
                    title: '审核详情',
                    area : ['80%' , '85%'],//弹出框大小
                    anim:1,
                    shadeClose:true,//点击也能遮罩层关闭
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    content: '/ok-admin/pages/audit/auditList.html?marketId='+marketId //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                });
            } else if(obj.event === 'edit'){
                var sid=data.sellId;
                var stype = data.sellType;
                console.info(sid);
                perUser = data;
                console.info(perUser);
                if(stype == 1){
                    onclose = layer.open({
                        type: 2,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['70%', '80%'], //宽高
                        content: 'wholesale.html?sellId='+sid,
                        end:function () {
                            // layer.msg("关闭ing");
                        }
                    });
                }
            } else if(obj.event === 'audit'){
                var url = "../../../immSell/updateStatus";
                var datas = {sellId:data.sellId};
                $.post(url,datas,function (objs) {
                    if (objs.status == 20){
                        // layer.msg(objs.message);
                        table.reload("testReload");
                    }else {
                        layer.msg(objs.message);
                    }
                },"json ")
            }
        });

    });

    /**
     * 关闭层
     */
    function closeOpen(msg) {
        layer.close(openIndex);
        layer.msg(msg, {time: 1000}, function () {
            table.reload("test");//刷新表格
        })
    }

    function query() {
        table.reload('testReload',{
            where:{
                searchParam:$("#searchParam").val()
            },
            page:{
                curr:1
            }
        })
    }

</script>

<script type="textml" id="typeTpl">
    {{#  if(d.isva == 10){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">未提交审核</span>
    {{#  } else if(d.isva == 20){ }}
    <span class="layui-btn layui-btn-warm layui-btn-xs">分公司总经理审核中</span>
    {{#  } else if(d.isva == 40){ }}
    <span class="layui-btn layui-btn-xs">分公司总经理审核通过</span>
    {{#  } else if(d.isva == 41){ }}
    <span class="layui-btn layui-btn-danger layui-btn-xs">分公司总经理审核不通过</span>
    {{#  } }}
</script>

</body>
</html>